package com.by.controller;

import cn.heimi.dto.OrderQueryDTO;
import cn.heimi.dto.OrderingDTO;
import cn.heimi.dto.OrderingOkDTO;
import cn.heimi.dto.ProductDTO;
import cn.hutool.core.thread.ThreadUtil;
import com.alibaba.nacos.common.utils.ThreadUtils;
import com.by.feignservice.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api/user")
public class UserController {
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private OrderService orderService;

    @GetMapping("/test")
    public String test() {
        return "user-service--->test";
    }

    @GetMapping("/shopping")
    public String getOrder() {
        String order = orderService.getOrder();
        return order;
    }

    @GetMapping("/shopping2")
    public OrderingOkDTO shopping2() {
        OrderingOkDTO orderingOkDTO = orderService.ordering2();
        return orderingOkDTO;
    }

    @GetMapping("/shopping3")
    public OrderingOkDTO shopping3() {
       List<ProductDTO> products = new ArrayList<>();
       products.add(new ProductDTO(1,"手机"));
       products.add(new ProductDTO(2,"电脑"));
       OrderingDTO orderingDTO = OrderingDTO.builder().userId(108).products(products).build();
        OrderingOkDTO orderingOkDTO = orderService.ordering3(orderingDTO);
        return orderingOkDTO;
    }
    @GetMapping("/order/select")
    public String orderSelect() {
        OrderQueryDTO orderQueryDTO = new OrderQueryDTO();
        orderQueryDTO.setUserId(108);
//        orderQueryDTO.setId(108);

        String msg = orderService.select(orderQueryDTO);
        return msg;
    }

@GetMapping("/sleep")
    public String sleep() {
    String sleep = orderService.sleep(5);
    return sleep;
    }

}